import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName:"login_home_welcome" */ '../views/Login.vue')
  },
  {
    
    path: '/home',
    name: 'home',
    component: () => import( /* webpackChunkName:"login_home_welcome" */ '../views/Home.vue'), redirect:'/welcome',
    children:[
      {
        path: '/welcome',
        name: 'welcome',
        component: () => import( /* webpackChunkName:"login_home_welcome" */'../components/welcome.vue'),
      },
      {
    
        path: '/users',
        name: 'users',
        component: () => import( /* webpackChunkName:"/users" */'../components/user/users'),
        meta:{
          bread:['用户管理','用户列表']
        }
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import( /* webpackChunkName:"/right_right" */ '../components/right/rights'),
        meta:{
          bread:['权限管理','权限列表']
        }
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import(  /* webpackChunkName:"/right_roles" */'../components/right/roles'),
        meta:{
          bread:['角色管理','角色列表']
        }
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import( /* webpackChunkName:"/goods_categories" */'../components/goods/categories'),
        meta:{
          bread:['商品管理','商品分类']
        }
      },
      {
        path: '/params',
        name: 'params',
        component: () => import( /* webpackChunkName:"/goods_params" */'../components/goods/params'),
        meta:{
          bread:['商品管理','参数列表']
        }
      },
      {
        path: '/reports',
        name: 'reports',
        component: () => import( /* webpackChunkName:"/report_reports" */'../components/report/reports'),
        meta:{
           bread:['数据统计','数据列表']
        }
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import(  /* webpackChunkName:"/goods_goods" */'../components/goods/goods'),
        meta:{
         bread:['商品列表','商品列表']
        }
      },
      {
        path: '/orders',
        name: 'orders',
        component: () => import(  /* webpackChunkName:"/orders_orders" */'../components/orders/orders'),
        meta:{
          bread:['订单管理','订单列表']
        }
      },
      {
        path: '/goods/add',
        name: 'add',
        component: () => import(  /* webpackChunkName:"goods_goods_add" */'../components/goods/add'),
        meta:{
          bread:['订单管理','订单列表']
        }
      },
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 挂载路由导航守卫
router.beforeEach((to,from,next) =>{
  if(to.path === '/login') return next()
 const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})
export default router
